<script setup lang="ts">
import { Todo } from '../types/todo';

interface Props {
  todo: Todo;
}

const props = defineProps<Props>();
const emit = defineEmits<{
  'toggle-complete': [id: number];
  'delete-todo': [id: number];
}>();

const toggleComplete = () => {
  emit('toggle-complete', props.todo.id);
};

const deleteTodo = () => {
  emit('delete-todo', props.todo.id);
};
</script>

<template>
  <div class="todo-item" :class="{ completed: todo.completed }">
    <div class="todo-content">
      <input
        type="checkbox"
        :checked="todo.completed"
        @change="toggleComplete"
        class="todo-checkbox"
      />
      <span class="todo-text">{{ todo.text }}</span>
    </div>
    <button @click="deleteTodo" class="delete-btn">
      <span>×</span>
    </button>
  </div>
</template>

<style scoped>
.todo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  margin-bottom: 8px;
  background-color: #2c2c2c;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.todo-content {
  display: flex;
  align-items: center;
  flex: 1;
}

.todo-checkbox {
  margin-right: 12px;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.todo-text {
  font-size: 16px;
  word-break: break-word;
  transition: all 0.3s ease;
}

.completed .todo-text {
  text-decoration: line-through;
  color: #888;
}

.delete-btn {
  background: none;
  border: none;
  color: #ff6b6b;
  font-size: 20px;
  cursor: pointer;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.delete-btn:hover {
  color: #ff4757;
  transform: scale(1.1);
}

@media (prefers-color-scheme: light) {
  .todo-item {
    background-color: #f5f5f5;
  }
}
</style>